using Circus.CodeEditor;
using Circus.CodeEditor.Serialization;
using Circus.CodeEditor.TextSource;
using Circus.Syntax;
using Circus.Syntax.Lexer;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Circus.CodeEditor.Dialogs
{
	public class SyntaxSettings : PersistentSettings
	{
		private ColorThemes colorThemes = new ColorThemes();
		private KeyData[] eventData = new KeyData[0];
		private LexStyles defaultLexStyles;
		private NavigateOptions navigateOptions;
		private RichTextBoxScrollBars scrollBars;
		private SelectionOptions selectionOptions;
		private GutterOptions gutterOptions;
		private SeparatorOptions separatorOptions;
		private OutlineOptions outlineOptions;
		private bool showMargin;
		private bool showGutter = true;
		private bool highlightHyperText = true;
		private bool allowOutlining;
		private bool useSpaces;
		private bool wordWrap;
		private bool whiteSpaceVisible = false;
		private int gutterWidth = EditConsts.DefaultGutterWidth;
		private int marginPos = EditConsts.DefaultMarginPosition;
		private int[] tabStops = new int[]
		{
			EditConsts.DefaultTabStop
		};
		private string[] eventNames = new string[0];
		private KeyList keyList = null;
		private int cColorStyles = -1;
	    private event HelpEventHandler helpRequested;
		public virtual event HelpEventHandler HelpRequested
		{
			add
			{
				this.helpRequested = (HelpEventHandler)Delegate.Combine(this.helpRequested, value);
			}
			remove
			{
				this.helpRequested = (HelpEventHandler)Delegate.Remove(this.helpRequested, value);
			}
		}
		public virtual ColorTheme DefaultColorTheme
		{
			get
			{
				return this.colorThemes[0];
			}
		}
		public virtual LexStyles LexStyles
		{
			get
			{
				return (this.colorThemes.ActiveTheme != null) ? this.colorThemes.ActiveTheme.LexStyles : null;
			}
			set
			{
				if (this.colorThemes.ActiveTheme != null)
				{
					this.colorThemes.ActiveTheme.LexStyles = value;
				}
			}
		}
		public virtual LexStyle[] DefaultLexStyles
		{
			get
			{
				LexStyle[] array = new LexStyle[this.defaultLexStyles.Count];
				this.defaultLexStyles.CopyTo(array, 0);
				return array;
			}
			set
			{
				this.defaultLexStyles.Clear();
				for (int i = 0; i < value.Length; i++)
				{
					LexStyle item = value[i];
					this.defaultLexStyles.Add(item);
				}
				this.DefaultColorTheme.LexStyles = this.defaultLexStyles;
			}
		}
		public virtual ColorThemes ColorThemes
		{
			get
			{
				return this.colorThemes;
			}
			set
			{
				if (this.colorThemes != value)
				{
					this.colorThemes = value;
					this.OnColorThemesChanged();
				}
			}
		}
		public virtual Font Font
		{
			get
			{
				return (this.colorThemes.ActiveTheme != null) ? this.colorThemes.ActiveTheme.Font : null;
			}
			set
			{
				if (this.colorThemes.ActiveTheme != null)
				{
					this.colorThemes.ActiveTheme.Font = value;
				}
			}
		}
		public virtual NavigateOptions NavigateOptions
		{
			get
			{
				return this.navigateOptions;
			}
			set
			{
				if (this.navigateOptions != value)
				{
					this.navigateOptions = value;
					this.OnNavigateOptionsChanged();
				}
			}
		}
		public virtual RichTextBoxScrollBars ScrollBars
		{
			get
			{
				return this.scrollBars;
			}
			set
			{
				if (this.scrollBars != value)
				{
					this.scrollBars = value;
					this.OnScrollBarsChanged();
				}
			}
		}
		public virtual SelectionOptions SelectionOptions
		{
			get
			{
				return this.selectionOptions;
			}
			set
			{
				if (this.selectionOptions != value)
				{
					this.selectionOptions = value;
					this.OnSelectionOptionsChanged();
				}
			}
		}
		public virtual GutterOptions GutterOptions
		{
			get
			{
				return this.gutterOptions;
			}
			set
			{
				if (this.gutterOptions != value)
				{
					this.gutterOptions = value;
					this.OnGutterOptionsChanged();
				}
			}
		}
		public virtual SeparatorOptions SeparatorOptions
		{
			get
			{
				return this.separatorOptions;
			}
			set
			{
				if (this.separatorOptions != value)
				{
					this.separatorOptions = value;
					this.OnSeparatorOptionsChanged();
				}
			}
		}
		public virtual OutlineOptions OutlineOptions
		{
			get
			{
				return this.outlineOptions;
			}
			set
			{
				if (this.outlineOptions != value)
				{
					this.outlineOptions = value;
					this.OnOutlineOptionsChanged();
				}
			}
		}
		public virtual bool ShowMargin
		{
			get
			{
				return this.showMargin;
			}
			set
			{
				if (this.showMargin != value)
				{
					this.showMargin = value;
					this.OnShowMarginChanged();
				}
			}
		}
		public virtual bool ShowGutter
		{
			get
			{
				return this.showGutter;
			}
			set
			{
				if (this.showGutter != value)
				{
					this.showGutter = value;
					this.OnShowGutterChanged();
				}
			}
		}
		public virtual bool HighlightHyperText
		{
			get
			{
				return this.highlightHyperText;
			}
			set
			{
				if (this.highlightHyperText != value)
				{
					this.highlightHyperText = value;
					this.OnHighlightHyperTextChanged();
				}
			}
		}
		public virtual bool AllowOutlining
		{
			get
			{
				return this.allowOutlining;
			}
			set
			{
				if (this.allowOutlining != value)
				{
					this.allowOutlining = value;
					this.OnAllowOutliningChanged();
				}
			}
		}
		public virtual bool UseSpaces
		{
			get
			{
				return this.useSpaces;
			}
			set
			{
				if (this.useSpaces != value)
				{
					this.useSpaces = value;
					this.OnUseSpacesChanged();
				}
			}
		}
		public virtual bool WordWrap
		{
			get
			{
				return this.wordWrap;
			}
			set
			{
				if (this.wordWrap != value)
				{
					this.wordWrap = value;
					this.OnWordWrapChanged();
				}
			}
		}
		public virtual bool WhiteSpaceVisible
		{
			get
			{
				return this.whiteSpaceVisible;
			}
			set
			{
				if (this.whiteSpaceVisible != value)
				{
					this.whiteSpaceVisible = value;
					this.OnWhiteSpaceVisibleChanged();
				}
			}
		}
		public virtual int GutterWidth
		{
			get
			{
				return this.gutterWidth;
			}
			set
			{
				if (this.gutterWidth != value)
				{
					this.gutterWidth = value;
					this.OnGutterWidthChanged();
				}
			}
		}
		public virtual int MarginPos
		{
			get
			{
				return this.marginPos;
			}
			set
			{
				if (this.marginPos != value)
				{
					this.marginPos = value;
					this.OnMarginPosChanged();
				}
			}
		}
		public virtual int[] TabStops
		{
			get
			{
				return this.tabStops;
			}
			set
			{
				if (this.tabStops != value)
				{
					this.tabStops = new int[value.Length];
					Array.Copy(value, this.tabStops, value.Length);
					this.OnTabStopsChanged();
				}
			}
		}
		public virtual string[] EventNames
		{
			get
			{
				return this.eventNames;
			}
			set
			{
				if (this.eventNames != value)
				{
					this.eventNames = value;
					this.OnEventNamesChanged();
				}
			}
		}
		public virtual KeyData[] EventData
		{
			get
			{
				return this.eventData;
			}
			set
			{
				if (this.eventData != value)
				{
					this.eventData = value;
					this.OnEventDataChanged();
				}
			}
		}
		
		public KeyList KeyList
		{
			get
			{
				return this.keyList;
			}
			set
			{
				this.keyList = value;
			}
		}
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
	
		private void CopyStyles(LexStyles fromStyles, LexStyles toStyles)
		{
			if (fromStyles != null && toStyles != null)
			{
				foreach (LexStyle current in fromStyles)
				{
					int styleByName = this.GetStyleByName(toStyles, current.Name);
					if (styleByName >= 0)
					{
						LexStyle lexStyle = toStyles[styleByName];
						lexStyle.Assign(current);
					}
				}
			}
		}
		private int GetStyleByName(LexStyles styles, string name)
		{
			int result;
			for (int i = 0; i < styles.Count; i++)
			{
				if (string.Compare(styles[i].Name, name, true) == 0)
				{
					result = i;
					return result;
				}
			}
			result = -1;
			return result;
		}
		private LexStyles GetLexStyles(CodeEditor edit)
		{
			return (edit.Source.Lexer != null) ? edit.Source.Lexer.Scheme.Styles : null;
		}
		protected virtual LexStyle InitDefaultStyle(string name, string desc, Color foreColor, Color backColor, FontStyle fontStyle, bool plainText)
		{
			LexStyle lexStyle = new LexStyle(null);
			lexStyle.Name = name;
			lexStyle.Desc = desc;
			lexStyle.ForeColor = foreColor;
			lexStyle.BackColor = backColor;
			lexStyle.FontStyle = fontStyle;
			lexStyle.PlainText = plainText;
			this.defaultLexStyles.Add(lexStyle);
			return lexStyle;
		}
		protected virtual LexStyle InitDefaultColorStyle(string name, string desc, Color foreColor, Color backColor)
		{
			LexStyle lexStyle = this.InitDefaultStyle(name, desc, foreColor, backColor, FontStyle.Regular, false);
			lexStyle.BackColorEnabled = (backColor != Color.Empty);
			lexStyle.ForeColorEnabled = (foreColor != Color.Empty);
			return lexStyle;
		}
		protected virtual void InitDefaultStyles()
		{
			this.defaultLexStyles.Clear();
			this.InitDefaultStyle(StringConsts.SymbolsInternalName, StringConsts.SymbolsName, SyntaxConsts.DefaultSymbolForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.IdentsInternalName, StringConsts.IdentsName, SyntaxConsts.DefaultIndentsForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.NumbersInternalName, StringConsts.NumbersName, SyntaxConsts.DefaultNumbersForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.ReswordsInternalName, StringConsts.ReswordsName, SyntaxConsts.DefaultReswordForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.CommentsInternalName, StringConsts.CommentsName, SyntaxConsts.DefaultCommentsForeColor, Color.Empty, FontStyle.Regular, true);
			this.InitDefaultStyle(StringConsts.StringsInternalName, StringConsts.StringsName, SyntaxConsts.DefaultStringsForeColor, Color.Empty, FontStyle.Regular, true);
			this.InitDefaultStyle(StringConsts.DirectivesInternalName, StringConsts.DirectivesName, SyntaxConsts.DefaultDirectivesForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.XMLCommentsInternalName, StringConsts.XMLCommentsName, SyntaxConsts.DefaultXmlCommentsForeColor, Color.Empty, FontStyle.Regular, true);
			this.InitDefaultStyle(StringConsts.HTMLParamsInternalName, StringConsts.HTMLParamsName, SyntaxConsts.DefaultHtmlParamsForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.WhiteSpaceInternalName, StringConsts.WhiteSpaceName, Consts.DefaultControlForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.LineNumbersInternalName, StringConsts.LineNumbersName, EditConsts.DefaultLineNumbersForeColor, Color.Empty, FontStyle.Regular, false);
			this.InitDefaultStyle(StringConsts.HyperTextInternalName, StringConsts.HyperTextName, EditConsts.DefaultHyperTextForeColor, Color.Empty, EditConsts.DefaultUrlFontStyle, false);
			this.InitDefaultStyle(StringConsts.MisspelledWordsInternalName, StringConsts.MisspelledWordsName, EditConsts.DefaultSpellForeColor, Color.Empty, FontStyle.Regular, false);
		}
		protected virtual void InitDefaultColorStyles()
		{
			this.InitDefaultColorStyle(StringConsts.WindowColorInternalName, StringConsts.WindowColorName, Color.Empty, Consts.DefaultControlBackColor);
			this.InitDefaultColorStyle(StringConsts.BraceMatchingInternalName, StringConsts.BraceMatchingName, EditConsts.DefaultBracesForeColor, EditConsts.DefaultBracesBackColor);
			this.InitDefaultColorStyle(StringConsts.GutterPenColorInternalName, StringConsts.GutterPenColorName, EditConsts.DefaultGutterForeColor, EditConsts.DefaultGutterBackColor);
			this.InitDefaultColorStyle(StringConsts.LineModificatorChangedInternalName, StringConsts.LineModificatorChangedName, EditConsts.DefaultLineModificatorChangedColor, Color.Empty);
			this.InitDefaultColorStyle(StringConsts.LineModificatorSavedInternalName, StringConsts.LineModificatorSavedName, EditConsts.DefaultLineModificatorSavedColor, Color.Empty);
			this.InitDefaultColorStyle(StringConsts.LineSeparatorInternalName, StringConsts.LineSeparatorName, EditConsts.DefaultLineSeparatorLineColor, Color.Empty);
			this.InitDefaultColorStyle(StringConsts.CodeOutlinePenColorInternalName, StringConsts.CodeOutlinePenColorName, EditConsts.DefaultOutlineForeColor, Color.Empty);
			this.InitDefaultColorStyle(StringConsts.ActiveSelectionInternalName, StringConsts.ActiveSelectionName, EditConsts.DefaultHighlightForeColor, EditConsts.DefaultHighlightBackColor);
			this.InitDefaultColorStyle(StringConsts.InactiveSelectionInternalName, StringConsts.InactiveSelectionName, EditConsts.DefaultInactiveHighlightForeColor, EditConsts.DefaultInactiveHighlightBackColor);
		}
		protected virtual void InitializeDefaultColorThemes()
		{
			this.InitDefaultStyles();
			this.cColorStyles = this.defaultLexStyles.Count;
			this.InitDefaultColorStyles();
			this.DefaultColorTheme.LexStyles = this.defaultLexStyles;
		}
		protected virtual void OnColorThemesChanged()
		{
		}
		protected virtual void OnNavigateOptionsChanged()
		{
		}
		protected virtual void OnScrollBarsChanged()
		{
		}
		protected virtual void OnSelectionOptionsChanged()
		{
		}
		protected virtual void OnGutterOptionsChanged()
		{
		}
		protected virtual void OnSeparatorOptionsChanged()
		{
		}
		protected virtual void OnOutlineOptionsChanged()
		{
		}
		protected virtual void OnShowMarginChanged()
		{
		}
		protected virtual void OnShowGutterChanged()
		{
		}
		protected virtual void OnHighlightHyperTextChanged()
		{
		}
		protected virtual void OnAllowOutliningChanged()
		{
		}
		protected virtual void OnUseSpacesChanged()
		{
		}
		protected virtual void OnWordWrapChanged()
		{
		}
		protected virtual void OnWhiteSpaceVisibleChanged()
		{
		}
		protected virtual void OnGutterWidthChanged()
		{
		}
		protected virtual void OnMarginPosChanged()
		{
		}
		protected virtual void OnTabStopsChanged()
		{
		}
		protected virtual void OnEventNamesChanged()
		{
		}
		protected virtual void OnEventDataChanged()
		{
		}
		public SyntaxSettings()
		{
			this.navigateOptions = EditConsts.DefaultNavigateOptions;
			this.scrollBars = RichTextBoxScrollBars.Both;
			this.selectionOptions = EditConsts.DefaultSelectionOptions;
			this.gutterOptions = EditConsts.DefaultGutterOptions;
			this.separatorOptions = SeparatorOptions.None;
			this.outlineOptions = EditConsts.DefaultOutlineOptions;
			this.gutterOptions |= EditConsts.DefaultGutterOptions;
			this.defaultLexStyles = new LexStyles(null);
			this.colorThemes.Add(new ColorTheme("Default", true, new Font(FontFamily.GenericMonospace, 10f), this.defaultLexStyles));
			this.colorThemes.ActiveThemeIndex = 0;
			this.InitializeDefaultColorThemes();
		}
	
		public override void Assign(PersistentSettings source)
		{
			if (source is SyntaxSettings)
			{
				SyntaxSettings syntaxSettings = (SyntaxSettings)source;
				this.navigateOptions = syntaxSettings.navigateOptions;
				this.scrollBars = syntaxSettings.scrollBars;
				this.selectionOptions = syntaxSettings.selectionOptions;
				this.gutterOptions = syntaxSettings.gutterOptions;
				this.separatorOptions = syntaxSettings.separatorOptions;
				this.outlineOptions = syntaxSettings.outlineOptions;
				this.showMargin = syntaxSettings.showMargin;
				this.showGutter = syntaxSettings.showGutter;
				this.highlightHyperText = syntaxSettings.highlightHyperText;
				this.allowOutlining = syntaxSettings.allowOutlining;
				this.useSpaces = syntaxSettings.useSpaces;
				this.wordWrap = syntaxSettings.wordWrap;
				this.whiteSpaceVisible = syntaxSettings.whiteSpaceVisible;
				this.gutterWidth = syntaxSettings.gutterWidth;
				this.marginPos = syntaxSettings.marginPos;
				this.TabStops = syntaxSettings.TabStops;
				this.DefaultLexStyles = syntaxSettings.DefaultLexStyles;
				this.eventNames = new string[syntaxSettings.EventNames.Length];
				syntaxSettings.EventNames.CopyTo(this.eventNames, 0);
				this.eventData = new KeyData[syntaxSettings.EventData.Length];
				syntaxSettings.EventData.CopyTo(this.eventData, 0);
				this.KeyList = syntaxSettings.KeyList;
			}
		}
		public virtual void LoadFromEdit(CodeEditor edit)
		{
			this.GutterOptions = edit.Gutter.Options;
			this.SeparatorOptions = edit.LineSeparator.Options;
			this.GutterWidth = edit.Gutter.Width;
			this.HighlightHyperText = edit.HyperText.HighlightHyperText;
			this.MarginPos = edit.EditMargin.Position;
			this.NavigateOptions = edit.NavigateOptions;
			this.AllowOutlining = edit.Outlining.AllowOutlining;
			this.OutlineOptions = edit.Outlining.OutlineOptions;
			this.ScrollBars = edit.Scrolling.ScrollBars;
			this.SelectionOptions = edit.Selection.Options;
			this.ShowGutter = edit.Gutter.Visible;
			this.ShowMargin = edit.EditMargin.Visible;
			this.TabStops = edit.Source.Lines.TabStops;
			this.UseSpaces = edit.Source.Lines.UseSpaces;
			this.WordWrap = edit.WordWrap;
			this.WhiteSpaceVisible = edit.WhiteSpace.Visible;
			this.EventNames = edit.KeyList.Handlers.EventNames;
			this.EventData = edit.KeyList.EventData;
			this.KeyList = (KeyList)edit.KeyList;
			this.Font = edit.Font;
			ColorTheme activeTheme = this.colorThemes.ActiveTheme;
			if (activeTheme != null)
			{
				if (activeTheme[StringConsts.WindowColorInternalName] != null)
				{
					activeTheme[StringConsts.WindowColorInternalName].BackColor = edit.BackColor;
				}
				if (activeTheme[StringConsts.MisspelledWordsInternalName] != null)
				{
					activeTheme[StringConsts.MisspelledWordsInternalName].ForeColor = edit.Spelling.SpellColor;
				}
				if (activeTheme[StringConsts.HyperTextInternalName] != null)
				{
					activeTheme[StringConsts.HyperTextInternalName].ForeColor = edit.HyperText.UrlColor;
					activeTheme[StringConsts.HyperTextInternalName].FontStyle = edit.HyperText.UrlStyle;
				}
				if (activeTheme[StringConsts.LineNumbersInternalName] != null)
				{
					activeTheme[StringConsts.LineNumbersInternalName].ForeColor = edit.Gutter.LineNumbersForeColor;
				}
				if (activeTheme[StringConsts.GutterPenColorInternalName] != null)
				{
					activeTheme[StringConsts.GutterPenColorInternalName].BackColor = edit.Gutter.BrushColor;
					activeTheme[StringConsts.GutterPenColorInternalName].ForeColor = edit.Gutter.PenColor;
				}
				if (activeTheme[StringConsts.WhiteSpaceInternalName] != null)
				{
					activeTheme[StringConsts.WhiteSpaceInternalName].ForeColor = edit.WhiteSpace.SymbolColor;
				}
				if (activeTheme[StringConsts.LineModificatorChangedInternalName] != null)
				{
					activeTheme[StringConsts.LineModificatorChangedInternalName].ForeColor = edit.Gutter.LineModificatorChangedColor;
				}
				if (activeTheme[StringConsts.LineModificatorSavedInternalName] != null)
				{
					activeTheme[StringConsts.LineModificatorSavedInternalName].ForeColor = edit.Gutter.LineModificatorSavedColor;
				}
				if (activeTheme[StringConsts.LineSeparatorInternalName] != null)
				{
					activeTheme[StringConsts.LineSeparatorInternalName].ForeColor = edit.LineSeparator.LineColor;
				}
				if (activeTheme[StringConsts.BraceMatchingInternalName] != null)
				{
					activeTheme[StringConsts.BraceMatchingInternalName].ForeColor = edit.Braces.ForeColor;
					activeTheme[StringConsts.BraceMatchingInternalName].BackColor = edit.Braces.BackColor;
				}
				if (activeTheme[StringConsts.CodeOutlinePenColorInternalName] != null)
				{
					activeTheme[StringConsts.CodeOutlinePenColorInternalName].ForeColor = edit.Outlining.OutlineColor;
				}
				if (activeTheme[StringConsts.ActiveSelectionInternalName] != null)
				{
					activeTheme[StringConsts.ActiveSelectionInternalName].ForeColor = edit.Selection.ForeColor;
				    activeTheme[StringConsts.ActiveSelectionInternalName].BackColor = edit.Selection.owner.selectionBackColor;
				}
				if (activeTheme[StringConsts.InactiveSelectionInternalName] != null)
				{
					activeTheme[StringConsts.InactiveSelectionInternalName].ForeColor = edit.Selection.InActiveForeColor;
				    activeTheme[StringConsts.InactiveSelectionInternalName].BackColor = edit.Selection.owner.inactivedSelectionBackColor;
				}
			}
		}
		public virtual void ApplyToEdit(CodeEditor edit)
		{
			this.ApplyToEdit(edit, true);
		}
		public virtual void ApplyToEdit(CodeEditor edit, bool withStyles)
		{
			edit.Source.BeginUpdate(UpdateReason.Other);
			try
			{
				edit.Outlining.AllowOutlining = this.AllowOutlining;
				edit.Outlining.OutlineOptions = this.OutlineOptions;
				edit.Font = this.Font;
				edit.Gutter.Options = this.GutterOptions;
				edit.LineSeparator.Options = this.SeparatorOptions;
				edit.Gutter.Width = this.GutterWidth;
				edit.EditMargin.Position = this.MarginPos;
				edit.NavigateOptions = this.NavigateOptions;
				edit.Scrolling.ScrollBars = this.ScrollBars;
				edit.Selection.Options = this.SelectionOptions;
				edit.Gutter.Visible = this.ShowGutter;
				edit.EditMargin.Visible = this.ShowMargin;
				edit.Source.Lines.TabStops = this.TabStops;
				edit.Source.Lines.UseSpaces = this.UseSpaces;
				edit.WordWrap = this.WordWrap;
				edit.WhiteSpace.Visible = this.WhiteSpaceVisible;
				if (withStyles)
				{
					this.CopyStyles(this.LexStyles, this.GetLexStyles(edit));
				}
				edit.HyperText.HighlightHyperText = this.HighlightHyperText;
				ColorTheme activeTheme = this.colorThemes.ActiveTheme;
				if (activeTheme != null)
				{
					if (activeTheme[StringConsts.MisspelledWordsInternalName] != null)
					{
						edit.Spelling.SpellColor = activeTheme[StringConsts.MisspelledWordsInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.HyperTextInternalName] != null)
					{
						edit.HyperText.UrlColor = activeTheme[StringConsts.HyperTextInternalName].ForeColor;
						edit.HyperText.UrlStyle = activeTheme[StringConsts.HyperTextInternalName].FontStyle;
					}
					if (activeTheme[StringConsts.LineNumbersInternalName] != null)
					{
						edit.Gutter.LineNumbersForeColor = activeTheme[StringConsts.LineNumbersInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.WindowColorInternalName] != null)
					{
						edit.Gutter.LineNumbersBackColor = activeTheme[StringConsts.WindowColorInternalName].BackColor;
					}
					if (activeTheme[StringConsts.GutterPenColorInternalName] != null)
					{
						edit.Gutter.BrushColor = activeTheme[StringConsts.GutterPenColorInternalName].BackColor;
						edit.Gutter.PenColor = activeTheme[StringConsts.GutterPenColorInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.WhiteSpaceInternalName] != null)
					{
						edit.WhiteSpace.SymbolColor = activeTheme[StringConsts.WhiteSpaceInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.LineModificatorChangedInternalName] != null)
					{
						edit.Gutter.LineModificatorChangedColor = activeTheme[StringConsts.LineModificatorChangedInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.LineModificatorSavedInternalName] != null)
					{
						edit.Gutter.LineModificatorSavedColor = activeTheme[StringConsts.LineModificatorSavedInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.LineSeparatorInternalName] != null)
					{
						edit.LineSeparator.LineColor = activeTheme[StringConsts.LineSeparatorInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.WindowColorInternalName] != null && activeTheme[StringConsts.WindowColorInternalName].BackColor != Color.Empty)
					{
						edit.BackColor = activeTheme[StringConsts.WindowColorInternalName].BackColor;
					}
					if (activeTheme[StringConsts.BraceMatchingInternalName] != null)
					{
						edit.Braces.ForeColor = activeTheme[StringConsts.BraceMatchingInternalName].ForeColor;
						edit.Braces.BackColor = activeTheme[StringConsts.BraceMatchingInternalName].BackColor;
					}
					if (activeTheme[StringConsts.CodeOutlinePenColorInternalName] != null)
					{
						edit.Outlining.OutlineColor = activeTheme[StringConsts.CodeOutlinePenColorInternalName].ForeColor;
					}
					if (activeTheme[StringConsts.ActiveSelectionInternalName] != null)
					{
						edit.Selection.ForeColor = activeTheme[StringConsts.ActiveSelectionInternalName].ForeColor;
					    edit.Selection.owner.selectionBackColor = activeTheme[StringConsts.ActiveSelectionInternalName].BackColor;
					}
					if (activeTheme[StringConsts.InactiveSelectionInternalName] != null)
					{
						edit.Selection.InActiveForeColor = activeTheme[StringConsts.InactiveSelectionInternalName].ForeColor;
					    edit.Selection.owner.inactivedSelectionBackColor = activeTheme[StringConsts.InactiveSelectionInternalName].BackColor;
					}
				}
			}
			finally
			{
				edit.Source.EndUpdate();
			}
			edit.Invalidate();
		}
		public void OnHelpRequest(object sender, HelpEventArgs e)
		{
			if (this.helpRequested != null)
			{
				this.helpRequested(this, e);
			}
		}
		public virtual bool IsDescriptionEnabled(int index)
		{
			return index >= 0 && this.colorThemes.ActiveTheme != null && this.colorThemes.ActiveTheme.LexStyles[index].Desc != string.Empty;
		}
		public virtual bool IsFontStyleEnabled(int index)
		{
			return index >= 0 && index < this.cColorStyles;
		}
		public virtual bool IsBackColorEnabled(int index)
		{
			return index >= 0 && this.colorThemes.ActiveTheme != null && this.colorThemes.ActiveTheme.LexStyles[index].BackColorEnabled;
		}
		public virtual void Localize()
		{
			this.InitializeDefaultColorThemes();
		}
	}
}
